﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Threading;

namespace Sinacor.Infra.Tools.LanguageGenerator
{
    public class ServiceController
    {
        public bool RunService
        {
            get;
            set;
        }

        public void ExecuteService()
        {
            DataAccess dataAccess = new DataAccess();
            XMLLanguageGenerator languageGenerator = new XMLLanguageGenerator();

            DateTime lastModification = dataAccess.GetLanguageLastChange();
            int timeToSleep = int.Parse(ConfigurationSettings.AppSettings["TimeToSleep"].ToString());

            while (RunService)
            {
                DateTime newModification = dataAccess.GetLanguageLastChange();

                if (lastModification != newModification)
                {
                    lastModification = newModification;
                    languageGenerator.GenerateLanguageXML(true);
                }
                else
                {
                    Thread.Sleep(timeToSleep);
                }
            }
        }
    }
}
